home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-12-14 | 35.5 KB | 1,333 lines |
- /*
- File: SamplePartUtils.c
-
- Contains: SamplePart utility functions & classes
-
- Written by: Steve Smith
-
- Copyright: © 1994,95 by Apple Computer, Inc., all rights reserved.
- */
-
- // -- Compiler/Preprocessor Notification --
-
- #ifndef _COMPILERDEFS_
- #include "CompDefs.h"
- #endif
-
- // -- OpenDoc Utilities --
-
- #ifndef _EXCEPT_
- // Exceptions define several important macros (ie. CHECKENV)
- // which are used in the SOM method dispatch glue. If Except.h
- // is not included early enough, exceptions may not be thrown
- // correctly when returning from a SOM method with the "ev" parameter set.
- #include <Except.h>
- #endif
-
- // --- SamplePart Includes ---
-
- #ifndef _SAMPLEPARTUTILS_
- #include "SamplePartUtils.h"
- #endif
-
- #ifndef _SAMPLEPARTDEF_
- #include "SamplePartDef.h"
- #endif
-
- // --- OpenDoc Includes ---
-
- #ifndef _ODTYPES_
- #include <ODTypes.h>
- #endif
-
- #ifndef SOM_ODPart_h
- #include <Part.h>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.h>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdTypes_defined
- #include <StdTypes.h>
- #endif
-
- #ifndef SOM_ODFrame_h
- #include <Frame.h>
- #endif
-
- #ifndef SOM_ODFrameFacetIterator_h
- #include <FrFaItr.h>
- #endif
-
- #ifndef SOM_ODDraft_h
- #include <Draft.h>
- #endif
-
- #ifndef SOM_ODStorageUnit_h
- #include <StorageU.h>
- #endif
-
- #ifndef SOM_ODStorageUnitView_h
- #include <SUView.h>
- #endif
-
- #ifndef SOM_ODNameSpaceManager_h
- #include <NmSpcMg.h>
- #endif
-
- #ifndef SOM_ODValueNameSpace_h
- #include <ValueNS.h>
- #endif
-
- #ifndef SOM_ODContainer_h
- #include <ODCtr.h>
- #endif
-
- #ifndef SOM_ODDocument_h
- #include <Document.h>
- #endif
-
- #ifndef SOM_ODWindowState_h
- #include <WinStat.h>
- #endif
-
- // --- OpenDoc Public Utilities ---
-
- #ifndef _MEMMGR_
- //#include <MemMgr.h>
- #endif
-
- #ifndef _STDTYPIO_
- #include "StdTypIO.h"
- #endif
-
- #ifndef _ITEXT_
- #include <IText.h>
- #endif
-
- #ifndef _ISOSTR_
- #include <ISOStr.h>
- #endif
-
- #ifndef _PASCLSTR_
- #include <PasclStr.h>
- #endif
-
- #ifndef _USERSRCM_
- #include <UseRsrcM.h>
- #endif
-
- #ifndef _ODUTILS_
- #include <ODUtils.h>
- #endif
-
- #ifndef _ODMEMORY_
- #include <ODMemory.h>
- #endif
-
- // --- Macintosh Includes ---
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- #ifndef __GXMATH__
- #include <GXMath.h>
- #endif
-
- #ifndef __SCRIPT__
- #include <Script.h>
- #endif
-
- #ifndef __TEXTUTILS__
- #include <TextUtils.h>
- #endif
-
- #pragma segment SamplePartUtilities
-
- //====================================================================
- // Utility Functions
- //====================================================================
-
- //==============================================================================
- #pragma mark • Functions •
- //==============================================================================
-
- //--------------------------------------------------------------------
- // NamesAreEquivalent
- //--------------------------------------------------------------------
-
- ODBoolean NamesAreEquivalent(Environment* ev, ODIText* fileName,
- ODIText* partName)
- {
- Str255 fileStr;
- Str255 partStr;
-
- // If the strings are in different languages, we're done.
- if ( (GetITextScriptCode(fileName) != GetITextScriptCode(partName)) ||
- GetITextLangCode(fileName) != GetITextLangCode(partName) )
- return kODFalse;
-
- GetITextPString(fileName, fileStr);
- GetITextPString(partName, partStr);
-
- // If the string lengths are different, we're done.
- if ( fileStr[0] != partStr[0] )
- return kODFalse;
-
- // Return the Toolbox string equivalence test.
- return EqualString(fileStr,partStr,kODTrue,kODTrue);
- }
-
- //------------------------------------------------------------------------------
- // ValueNameSpaceGetODName (from NmSpcUtl.cpp)
- // Method included here because source file will not compile using C compiler.
- //------------------------------------------------------------------------------
-
- ODBoolean ValueNameSpaceGetODName(ODValueNameSpace* ns,
- Environment* ev,
- ODISOStr key,
- ODName** value)
- {
- ODByteArray ba;
- ODULong textLen = 0;
- StringPtr thePString;
-
- if (ODValueNameSpace_GetEntry(ns, ev, key, &ba))
- {
- ODTradITextData* theIName = (ODTradITextData*)ODNewPtrClear(ba._length, kDefaultHeapID);
- ODBlockMove(ba._buffer, theIName, ba._length);
- ODDisposePtr( ba._buffer );
- textLen = ba._length - sizeof(ODTradITextDataHeader);
- thePString = (StringPtr)ODNewPtrClear(textLen+1, kODNULL);
- thePString[0] = textLen;
- ODBlockMove((ODPtr)theIName->theText, (ODPtr)&thePString[1], textLen );
- *value = CreateITextPString(theIName->theScriptCode,
- theIName->theLangCode,
- thePString);
- ODDisposePtr( theIName );
- ODDisposePtr( thePString );
- return kODTrue;
- }
- else
- {
- *value = kODNULL;
- return kODFalse;
- }
- }
-
- //------------------------------------------------------------------------------
- // GetUserCatFromCat (from BndNSUtl.cpp)
- // Method included here because source file will not compile using C compiler.
- //------------------------------------------------------------------------------
-
- ODBoolean GetUserCatFromCat(ODNameSpaceManager* theNmSpcMgr,
- ODType category, ODIText** name)
- {
- ODValueNameSpace* userStringNameSpace;
- ODBoolean result = kODFalse;
- Environment* ev = somGetGlobalEnvironment();
-
- // look it up in the spaceName namespace
- userStringNameSpace = (ODValueNameSpace*)
- ODNameSpaceManager_HasNameSpace(theNmSpcMgr, ev, kODCategoryUserString);
-
- if (userStringNameSpace)
- result = ValueNameSpaceGetODName(userStringNameSpace, ev,
- category, name);
- return result ;
- }
-
- //--------------------------------------------------------------------
- // GetPartName
- //--------------------------------------------------------------------
-
- ODIText* GetPartName(Environment* ev, ODPart* part, ODType category)
- {
- ODDraft* draft = kODNULL;
- ODPart* rootPart = kODNULL;
- ODIText* partName = kODNULL;
- ODContainer* container = kODNULL;
- ODDocument* document = kODNULL;
- ODIText* categoryName;
- ODNameSpaceManager* nsMgr;
- ODSession* session;
- ODStorageUnit* su;
-
- if (part != kODNULL)
- {
-
- // Get the root part of the document.
- draft = ODGetDraftFromPart(ev,part);
- su = ODDraft_AcquireDraftProperties( draft, ev );
- rootPart = ODDraft_AcquirePart(draft, ev, ODGetStrongSURefProp(ev, su, kODPropRootPartSU, kODStrongStorageUnitRef));
- ODReleaseObject(ev, su);
-
- // Get the part name.
- // If we can't get a valid name for the part, we generate one using
- // the user visible category name of the part's category.
- partName = ODGetITextProp(ev, ODPart_GetStorageUnit(part, ev),
- kODPropName, kODMacIText, kODNULL);
-
- if ( (partName == kODNULL) || (GetITextStringLength(partName) == 0) )
- {
- session = ODGetSessionFromPart(ev,part);
- nsMgr = ODSession_GetNameSpaceManager(session, ev);
-
- // Get the category string from the category name space.
- if ( GetUserCatFromCat(nsMgr, category, &categoryName) )
- {
- // If we successfully retrieved the category user string, return it.
- // (This code transfers the ODIText object to the partName tempobj)
- DisposeIText(partName);
- partName = categoryName;
- }
- else
- {
- #if ODDebug
- // This should never happen. Check NMAP for errors.
- DebugStr("\pCategory NMAP bad, or nmap cache file corrupted.");
- #else
- THROW(kODErrInvalidNSType);
- #endif
- }
- }
-
- ODReleaseObject(ev, rootPart);
- }
-
- return partName;
- }
-
- //--------------------------------------------------------------------
- // GetEditorScriptLanguage
- //--------------------------------------------------------------------
-
- void GetEditorScriptLanguage(Environment* ev, ODScriptCode* script,
- ODLangCode* language)
- {
- OSErr error = noErr;
- long region;
- ODSLong rfRef;
-
- rfRef = BeginUsingLibraryResources();
- {
- Handle versHdl = GetResource('vers', 1);
-
- // Get the region code of the editor, otherwise use the
- // region code the of the primary system script.
-
- if ( versHdl )
- {
- region = (long)(*(VersRecHndl)versHdl)->countryCode;
- ReleaseResource(versHdl);
- }
- else
- {
- region = GetScriptManagerVariable(smRegionCode);
- }
-
- // Spanish & Japanese are not actually supported by the editor.
- // They are provided as examples of how to add recognition of
- // additional regions (see Script.h for region codes).
-
- switch ((short)region) {
- case verUS:
- *script = smRoman;
- *language = langEnglish;
- break;
- case verSpain:
- *script = smRoman;
- *language = langSpanish;
- break;
- case verJapan:
- *script = smJapanese;
- *language = langJapanese;
- break;
- default:
- *script = smRoman;
- *language = langEnglish;
- }
- }
- EndUsingLibraryResources(rfRef);
- }
-
- //--------------------------------------------------------------------
- // FixedToIntRect
- //--------------------------------------------------------------------
-
- void FixedToIntRect(ODRect* fixedRect, Rect* intRect)
- {
- intRect->top = FixedToInt(fixedRect->top);
- intRect->left = FixedToInt(fixedRect->left);
- intRect->bottom = FixedToInt(fixedRect->bottom);
- intRect->right = FixedToInt(fixedRect->right);
- }
-
- //--------------------------------------------------------------------
- // IntToFixedRect
- //--------------------------------------------------------------------
-
- void IntToFixedRect(Rect* intRect, ODRect* fixedRect)
- {
- fixedRect->left = ff(intRect->left);
- fixedRect->top = ff(intRect->top);
- fixedRect->right = ff(intRect->right);
- fixedRect->bottom = ff(intRect->bottom);
- }
-
- //--------------------------------------------------------------------
- // LoadThumbnail
- //--------------------------------------------------------------------
-
- void LoadThumbnail(Environment* ev, Handle* thumbnail)
- {
- ODSLong rfRef;
-
- if ( *thumbnail ) return;
-
- rfRef = BeginUsingLibraryResources();
- {
- *thumbnail = (Handle) GetPicture(kThumbnailPicture);
- }
- EndUsingLibraryResources(rfRef);
- }
-
- //--------------------------------------------------------------------
- // TilePartWindow
- //--------------------------------------------------------------------
-
- Rect TilePartWindow(Environment* ev, Rect* facetBounds, Rect* partWindowBounds)
- {
- const short kWindowTilingConst = 20;
- const short kLeftToRight = 0;
- const short kRightToLeft = -1;
-
- short direction;
-
- // Get the direction for the primary script system running on this machine.
- // (Right-to-Left or Left-to-Right)
- direction = GetSysDirection();
-
- // The part window should be tiled from the topLeft corner of the
- // active facet who's frame is being opened.
- if ( direction == kLeftToRight )
- {
- // Position the window rect at the top/left corner of the facet.
- OffsetRect(partWindowBounds, facetBounds->left, facetBounds->top);
- // Now tile the window rect down and to the right.
- OffsetRect(partWindowBounds, kWindowTilingConst, kWindowTilingConst);
- }
- // The part window should be tiled from the topRight corner of the
- // active facet who's frame is being opened.
- else if ( direction == kRightToLeft )
- {
- // Position the window rect at the top/right corner of the facet.
- OffsetRect(partWindowBounds, (partWindowBounds->right - facetBounds->right),
- facetBounds->top);
- // Now tile the window rect down and to the left.
- OffsetRect(partWindowBounds, -kWindowTilingConst, kWindowTilingConst);
- }
-
- return *partWindowBounds;
- }
-
- //--------------------------------------------------------------------
- // CountFacets
- //--------------------------------------------------------------------
-
- ODUShort CountFramesFacets(Environment* ev, ODFrame* frame)
- {
- ODUShort facetCount = 0;
- ODFacet* facet;
- ODFrameFacetIterator* ffiter;
-
- ODVolatile(ffiter);
-
- TRY
- ffiter = ODFrame_CreateFacetIterator(frame, ev);
- CHECK_ENV(ev);
-
- facet = ODFrameFacetIterator_First(ffiter, ev);
- CHECK_ENV(ev);
-
- while ( ODFrameFacetIterator_IsNotComplete(ffiter, ev) )
- {
- CHECK_ENV(ev);
-
- facetCount++;
-
- facet = ODFrameFacetIterator_Next(ffiter, ev);
- CHECK_ENV(ev);
- }
- ODDeleteObject_C(ffiter);
-
- CATCH_ALL
- ODDeleteObject_C(ffiter);
- ENDTRY
-
- return facetCount;
- }
-
- //------------------------------------------------------------------------------
- // Replacements for overloaded functions from ODUtils.cpp
- //------------------------------------------------------------------------------
-
- ODDraft* ODGetDraftFromPart( Environment *ev, ODPart *p )
- {
- return p ?ODStorageUnit_GetDraft(ODPart_GetStorageUnit(p,ev), ev) :kODNULL;
- }
-
- ODDraft* ODGetDraftFromSU( Environment *ev, ODStorageUnit *su )
- {
- return su ?ODStorageUnit_GetDraft(su, ev) :kODNULL;
- }
-
- ODSession* ODGetSessionFromPart( Environment *ev, ODPart *p )
- {
- return p ?ODStorageUnit_GetSession(ODPart_GetStorageUnit(p,ev), ev) :kODNULL;
- }
-
- //----------------------------------------------------------------------------------------
- // StorageUnitGetValue_C
- //
- // copied from OpenDoc's StorUtil.cpp.
- //----------------------------------------------------------------------------------------
- ODULong StorageUnitGetValue_C(ODStorageUnit* su,
- Environment* ev,
- ODULong size,
- ODPtr buffer)
- {
- ODByteArray ba;
- ODULong bytesRead = ODStorageUnit_GetValue(su, ev, size, &ba);
- BlockMove(ba._buffer, buffer, bytesRead);
- ODDisposePtr((Ptr)ba._buffer);
-
- return bytesRead;
- }
-
- //----------------------------------------------------------------------------------------
- // CStorageUnitSetValue_C
- //----------------------------------------------------------------------------------------
- void StorageUnitSetValue_C(ODStorageUnit* su,
- Environment* ev,
- ODULong size,
- const void *buffer)
- {
- ODByteArray ba;
- ba._length = size;
- ba._maximum = size;
- ba._buffer = (octet*) buffer;
- ODStorageUnit_SetValue(su, ev, &ba);
- }
-
- //==============================================================================
- // CopyAndRelease // similar to 0
- //==============================================================================
-
- ODShape* CopyAndRelease( Environment *ev, ODShape *s )
- {
- ODShape* tempS = kODNULL;
- ODShape *copy = kODNULL;
-
- if( ODShape_GetRefCount(s, ev) == 1 )
- return s;
- tempS = s; // Ensures that s gets released
- copy = ODShape_Copy(s, ev);
- ODReleaseObject(ev, tempS );
-
- return copy;
- }
-
- //==============================================================================
- #pragma mark • CLinkedList •
- //==============================================================================
-
- //====================================================================
- // CLinkedList
- //====================================================================
-
- CLinkedList CLinkedList_Create()
- {
- CLinkedList list;
-
- list = (CLinkedList) ODNewPtrClear(sizeof(CLink), kODNULL);
-
- if ( list != kODNULL )
- {
- list->content = kODNULL;
- list->prev = list;
- list->next = list;
- }
-
- return list;
- }
-
-
- void CLinkedList_Delete(CLinkedList list)
- {
- if (list )
- {
- // Delete all links:
- while ( list->next != list )
- {
- CLinkedList_Remove(list, list->next->content);
- }
- ODDisposePtr((ODPtr)list);
- list = kODNULL;
- }
- }
-
-
- void CLinkedList_Add(CLinkedList list, ODPtr content)
- {
- CLink* link;
-
- link = (CLinkedList) ODNewPtrClear(sizeof(CLink), kODNULL);
-
- if ( link != kODNULL )
- {
- link->content = content;
- link->prev = list;
- link->next = list->next;
-
- list->next->prev = link;
- list->next = link;
- }
- }
-
-
- void
- CLinkedList_Remove(CLinkedList list, ODPtr content)
- {
- CLink* link;
- CLink* last;
-
- last = list;
-
- for (link = list->next ; link->content ; link = link->next)
- {
- if (link->content == content)
- {
- last->next = link->next;
- link->next->prev = last;
-
- ODDisposePtr((ODPtr)link);
- link = kODNULL;
- return;
- }
-
- last = link;
- }
- }
-
- CLink*
- CLinkedList_First(CLinkedList list)
- {
- if (list)
- return list->next;
- else
- return kODNULL;
- }
-
- ODBoolean
- CLinkedList_Contains(CLinkedList list, ODPtr content)
- {
- CLink *link;
- for (link = list->next ; link->content ; link = link->next)
- {
- if (link->content == content)
- return kODTrue;
- }
-
- return kODFalse;
- }
-
-
- ODUShort
- CLinkedList_Count(CLinkedList list)
- {
- ODUShort count = 0;
- CLink *link;
- for (link = list->next ; link->content ; link = link->next)
- count++;
-
- return count;
- }
-
-
- //====================================================================
- // CLink
- //====================================================================
-
- ODPtr
- CLink_Content(CLink* link)
- {
- if (link)
- return link->content;
- else
- return kODNULL;
- }
-
- CLink*
- CLink_Next(CLink* link)
- {
- if (link)
- return link->next;
- else
- return kODNULL;
- }
-
- //=========================================================================
- // CFrameProxy
- //=========================================================================
-
- //==============================================================================
- #pragma mark • CFrameProxy •
- //==============================================================================
-
- //-------------------------------------------------------------------------
- // CFrameProxy_Create
- //-------------------------------------------------------------------------
-
- CFrameProxy* CFrameProxy_Create()
- {
- CFrameProxy* fp = kODNULL;
-
- fp = (CFrameProxy*) ODNewPtrClear(sizeof(CFrameProxy), kODNULL);
-
- if ( fp != kODNULL )
- {
- fp->fFrame = kODNULL;
- fp->fID = kODNULLID;
- fp->fDraft = kODNULL;
- }
-
- return fp;
- }
-
- //-------------------------------------------------------------------------
- // CFrameProxy_Delete
- //-------------------------------------------------------------------------
-
- void CFrameProxy_Delete(CFrameProxy** fp, Environment* ev)
- {
- if ( *fp )
- {
- ODSafeReleaseObject((*fp)->fFrame);
- ODDisposePtr((ODPtr)(*fp));
- *fp = kODNULL;
- }
- }
-
- //-------------------------------------------------------------------------
- // CFrameProxy_InitFrameProxyDraft
- //-------------------------------------------------------------------------
- void CFrameProxy_InitFrameProxyWithID(CFrameProxy* fp, ODID frameID, ODDraft* draft)
- {
- fp->fFrame = kODNULL;
- fp->fID = frameID;
- fp->fDraft = draft;
- }
-
- //-------------------------------------------------------------------------
- // CFrameProxy_InitFrameProxyFrame
- //-------------------------------------------------------------------------
- void CFrameProxy_InitFrameProxyWithFrame(CFrameProxy* fp, Environment* ev, ODFrame* frame)
- {
- CFrameProxy_SetFrame(fp, ev,frame);
- }
-
- //-------------------------------------------------------------------------
- // CFrameProxy_Purge
- //-------------------------------------------------------------------------
- void CFrameProxy_Purge(CFrameProxy* fp, Environment* ev)
- {
- if ( fp->fFrame )
- {
- fp->fID = ODFrame_GetID(fp->fFrame, ev);
- ODReleaseObject(ev, fp->fFrame);
- }
- }
-
- //-------------------------------------------------------------------------
- // CFrameProxy_GetFrame
- //-------------------------------------------------------------------------
- ODFrame* CFrameProxy_GetFrame(CFrameProxy* fp, Environment* ev)
- {
- ODFrame* frame = kODNULL;
- ODVolatile( frame );
-
- if ( fp->fFrame == kODNULL )
- {
- TRY
- ODFrame* frame = ODDraft_AcquireFrame(fp->fDraft, ev, fp->fID);
- CHECK_ENV(ev);
-
- CFrameProxy_SetFrame(fp, ev, frame);
- CHECK_ENV(ev);
-
- ODReleaseObject(ev, frame);
- CATCH_ALL
- ODSafeReleaseObject(frame);
- fp->fFrame = kODNULL;
- fp->fID = kODNULLID;
- ENDTRY
- }
- return fp->fFrame;
- }
-
- //-------------------------------------------------------------------------
- // CFrameProxy_SetFrame
- //-------------------------------------------------------------------------
- void CFrameProxy_SetFrame(CFrameProxy* fp, Environment* ev, ODFrame* frame)
- {
- ODID id = kODNULLID;
- ODDraft* draft = kODNULL;
- ODPart* tPart = kODNULL;
-
- TRY
- // Using the temp object will cleanup the incoming
- // frame's refcount if something goes wrong.
- ODFrame_Acquire(frame, ev);
- CHECK_ENV(ev);
-
- // Perform all the operations that can fail, first.
- tPart = ODFrame_AcquirePart(frame, ev);
- CHECK_ENV(ev);
-
- id = ODFrame_GetID(frame, ev);
- CHECK_ENV(ev);
-
- draft = ODGetDraftFromPart(ev, tPart);
- CHECK_ENV(ev);
-
- ODReleaseObject(ev, fp->fFrame);
- CHECK_ENV(ev);
-
- // If all went well, set the proxy fields.
- fp->fFrame = frame;
- fp->fID = id;
- fp->fDraft = draft;
-
- ODReleaseObject(ev, tPart);
- CATCH_ALL
- ODSafeReleaseObject(tPart);
- ENDTRY
- }
-
- //-------------------------------------------------------------------------
- // CFrameProxy_FrameIsLoaded
- //-------------------------------------------------------------------------
- ODBoolean CFrameProxy_FrameIsLoaded(CFrameProxy* fp, Environment* ev)
- {
- ODBoolean loaded = (fp->fFrame != kODNULL ||
- ODDraft_IsValidID(fp->fDraft, ev, fp->fID));
- return loaded;
- }
-
- //-------------------------------------------------------------------------
- // CFrameProxy_GetID
- //-------------------------------------------------------------------------
- ODID CFrameProxy_GetID(CFrameProxy* fp )
- {
- return fp->fID;
- }
-
- //-------------------------------------------------------------------------
- // CFrameProxy_GetDraft
- //-------------------------------------------------------------------------
- ODDraft* CFrameProxy_GetDraft(CFrameProxy* fp )
- {
- return fp->fDraft;
- }
-
- //=========================================================================
- // CFrameInfo
- //=========================================================================
-
- //==============================================================================
- #pragma mark • CFrameInfo •
- //==============================================================================
-
- //-------------------------------------------------------------------------
- // CFrameInfo_Create
- //-------------------------------------------------------------------------
-
-
- CFrameInfo* CFrameInfo_Create(ODSession* session)
- {
- CFrameInfo* fi;
-
- fi = (CFrameInfo*) ODNewPtrClear(sizeof(CFrameInfo), kODNULL);
-
- if ( fi != kODNULL )
- {
- fi->fSession = session;
- fi->fFrameActive = kODFalse;
- fi->fFrameReactivate = kODFalse;
- fi->fShouldDisposeWindow = kODFalse;
- fi->fActiveFacet = kODNULL;
- fi->fSourceFrame = kODNULL;
- fi->fDependentFrame = kODNULL;
- fi->fPartWindowID = kODNULLID;
- }
-
- return fi;
- }
-
- //-------------------------------------------------------------------------
- // CFrameInfo_Delete
- //-------------------------------------------------------------------------
-
- void CFrameInfo_Delete(CFrameInfo** fi, Environment* ev)
- {
- CFrameProxy_Delete( &((*fi)->fSourceFrame), ev );
- CFrameProxy_Delete( &((*fi)->fDependentFrame), ev );
-
- ODDisposePtr((ODPtr)(*fi));
- *fi = kODNULL;
- }
-
- //-------------------------------------------------------------------------
- // CFrameInfo_Externalize
- //-------------------------------------------------------------------------
-
- void CFrameInfo_Externalize(CFrameInfo* fi, Environment* ev, ODStorageUnitView* storageUnitView)
- {
- // This method assumes that OpenDoc has passed us a storageUnitView
- // that is focused to a property, but no particular value.
-
- ODStorageUnit* storageUnit = ODStorageUnitView_GetStorageUnit(storageUnitView, ev);
-
- CFrameInfo_CleanseFrameInfoProperty(fi, ev, storageUnit);
- CFrameInfo_ExternalizeFrameInfo(fi, ev, storageUnit, kODNULLKey, kODNULL);
- }
-
- //-------------------------------------------------------------------------
- // CFrameInfo::CleanseFrameInfoProperty
- //-------------------------------------------------------------------------
-
- void CFrameInfo_CleanseFrameInfoProperty(CFrameInfo* fi, Environment* ev, ODStorageUnit* storageUnit)
- {
- ODULong numValues;
- ODULong index;
- ODValueType value;
-
- numValues = ODStorageUnit_CountValues(storageUnit, ev);
-
- for (index = numValues; index >= 1; index--)
- {
- // Index from 1 to n through the values.
- ODStorageUnit_Focus(storageUnit, ev, kODNULL, kODPosSame,
- kODNULL, index, kODPosUndefined);
-
- // Get the ISO type name for the value. The storage unit
- // will allocate memory for the returned ISOStr.
- value = ODStorageUnit_GetType(storageUnit, ev);
-
- // If the value type is not one we support, remove it.
- if ( ODISOStrCompare(value, kSamplePartInfo) != 0 )
- ODStorageUnit_Remove(storageUnit, ev);
-
- ODDisposePtr(value);
- }
- }
-
- //-------------------------------------------------------------------------
- // CFrameInfo::ExternalizeFrameInfo
- //-------------------------------------------------------------------------
-
- void CFrameInfo_ExternalizeFrameInfo(CFrameInfo* fi, Environment* ev,
- ODStorageUnit* storageUnit,
- ODDraftKey key,
- ODFrame* scopeFrame)
- {
- // This method behaves much the same way as the
- // SamplePart::ExternalizeStateInfo method.
-
- if ( ODStorageUnit_Exists(storageUnit, ev, kODNULL, kSamplePartInfo, 0) )
- {
- // Persistent object references are stored in a side table, rather than
- // in the property/value stream. Thus, deleting the contents of a value
- // will not "delete" the references previously written to that value. To
- // completely "delete" all references written to the value, we must
- // remove the value and add it back.
-
- ODStorageUnit_Focus(storageUnit, ev, kODNULL, kODPosSame, kSamplePartInfo, 0 , kODPosUndefined);
- ODStorageUnit_Remove(storageUnit, ev);
- }
-
- // Add a value to write the data into.
- ODStorageUnit_AddValue(storageUnit, ev, kSamplePartInfo);
-
- // Write a weak reference to our source frame.
- {
- ODStorageUnitRef weakRef = {0,0,0,0};
-
- if ( fi->fSourceFrame )
- {
- ODID frameID;
- ODID scopeFrameID;
- ODDraft* fromDraft;
-
- frameID = CFrameProxy_GetID(fi->fSourceFrame);
- scopeFrameID = ( scopeFrame ? ODFrame_GetID(scopeFrame, ev) : 0 );
- fromDraft = CFrameProxy_GetDraft(fi->fSourceFrame);
-
- // If a draft key exists, then we are being cloned to another draft.
- // We must "weak" clone our display frame and reference the cloned
- // frame. The part re-uses the frameID variable so there aren't two
- // different GetWeakStorageUnitRef calls.
- if ( key )
- frameID = ODDraft_WeakClone(fromDraft, ev, key, frameID,
- kODNULLID, scopeFrameID);
-
- // Write out weak references to each of the part's display frames.
- ODStorageUnit_GetWeakStorageUnitRef(storageUnit, ev, frameID, weakRef);
- }
- StorageUnitSetValue_C(storageUnit, ev, sizeof(ODStorageUnitRef), (ODPtr)&weakRef);
- }
-
- // Write a weak reference to our dependent frame.
- {
- ODStorageUnitRef weakRef = {0,0,0,0};
-
- if ( fi->fDependentFrame )
- {
- ODID frameID;
- ODID scopeFrameID;
- ODDraft* fromDraft;
-
- frameID = CFrameProxy_GetID(fi->fDependentFrame);
- scopeFrameID = ( scopeFrame ? ODFrame_GetID(scopeFrame, ev) : 0 );
- fromDraft = CFrameProxy_GetDraft(fi->fDependentFrame);
-
- // If a draft key exists, then we are being cloned to another draft.
- // We must "weak" clone our display frame and reference the cloned
- // frame. The part re-uses the frameID variable so there aren't two
- // different GetWeakStorageUnitRef calls.
- if ( key )
- frameID = ODDraft_WeakClone(fromDraft, ev, key, frameID,
- kODNULLID, scopeFrameID);
-
- // Write out weak references to each of the part's display frames.
- ODStorageUnit_GetWeakStorageUnitRef(storageUnit, ev, frameID, weakRef);
- }
- StorageUnitSetValue_C(storageUnit, ev, sizeof(ODStorageUnitRef), (ODPtr)&weakRef);
- }
- }
-
- //-------------------------------------------------------------------------
- // CFrameInfo::CloneInto
- //-------------------------------------------------------------------------
-
- void CFrameInfo_CloneInto(CFrameInfo* fi, Environment *ev, ODDraftKey key,
- ODStorageUnitView* storageUnitView,
- ODFrame* scopeFrame)
- {
- // This method assumes that OpenDoc has passed us a storageUnitView
- // that is focused to a property, but no particular value.
-
- ODStorageUnit* storageUnit =
- ODStorageUnitView_GetStorageUnit(storageUnitView, ev);
-
- if ( ODStorageUnit_Exists(storageUnit, ev, kODNULL, kSamplePartInfo, 0)
- == kODFalse )
- {
- CFrameInfo_ExternalizeFrameInfo(fi, ev, storageUnit, key, scopeFrame);
- }
- }
-
- //-------------------------------------------------------------------------
- // CFrameInfo::InitFromStorage
- //-------------------------------------------------------------------------
-
- void CFrameInfo_InitFromStorage(CFrameInfo* fi, Environment* ev,
- ODStorageUnitView* storageUnitView)
- {
- // This method assumes that OpenDoc has passed us a storageUnitView
- // that is focused to a property, but no particular value.
-
- ODULong size;
- ODStorageUnitRef weakRef = {0,0,0,0};
- ODStorageUnitRef weakRef2 = {0,0,0,0};
- CFrameProxy* proxy = kODNULL;
- CFrameProxy* proxy2 = kODNULL;
- ODID frameID;
- ODStorageUnit* storageUnit =
- ODStorageUnitView_GetStorageUnit(storageUnitView, ev);
-
- if ( ODStorageUnit_Exists(storageUnit, ev, kODNULL, kSamplePartInfo, 0) )
- {
- TRY
- ODStorageUnit_Focus(storageUnit, ev, kODNULL, kODPosSame,
- kSamplePartInfo, 0 , kODPosUndefined);
- CHECK_ENV(ev);
-
- size = ODStorageUnit_GetSize(storageUnit, ev);
- CHECK_ENV(ev);
-
- StorageUnitGetValue_C(storageUnit, ev, sizeof(ODStorageUnitRef),
- (ODPtr)&weakRef);
- CHECK_ENV(ev);
-
- if ( ODStorageUnit_IsValidStorageUnitRef(storageUnit, ev, weakRef) )
- {
- // Convert the reference into a runtime id.
- frameID = ODStorageUnit_GetIDFromStorageUnitRef(storageUnit, ev, weakRef);
- CHECK_ENV(ev);
-
- // Create a proxy class to support the lazy internalization.
- proxy = CFrameProxy_Create();
- CFrameProxy_InitFrameProxyWithID(proxy, frameID, ODGetDraftFromSU(ev,storageUnit));
-
- // Store the proxy source frame.
- fi->fSourceFrame = proxy;
- }
- else
- {
- fi->fSourceFrame = kODNULL;
- }
- CHECK_ENV(ev);
-
-
- CATCH_ALL
- CFrameProxy_Delete(&(fi->fSourceFrame), ev);
- ENDTRY
-
- TRY
- StorageUnitGetValue_C(storageUnit, ev, sizeof(ODStorageUnitRef),
- (ODPtr)&weakRef);
- CHECK_ENV(ev);
-
- if ( ODStorageUnit_IsValidStorageUnitRef(storageUnit, ev, weakRef) )
- {
- // Convert the reference into a runtime id.
- frameID = ODStorageUnit_GetIDFromStorageUnitRef(storageUnit, ev, weakRef);
- CHECK_ENV(ev);
-
- // Create a proxy class to support the lazy internalization.
- proxy2 = CFrameProxy_Create();
- CFrameProxy_InitFrameProxyWithID(proxy, frameID, ODGetDraftFromSU(ev,storageUnit));
-
- // Store the proxy dependent frame.
- fi->fDependentFrame = proxy;
- }
- else
- {
- fi->fDependentFrame = kODNULL;
- }
- CHECK_ENV(ev);
-
- CATCH_ALL
- CFrameProxy_Delete(&(fi->fDependentFrame), ev);
- ENDTRY
- }
- }
-
-
- //-------------------------------------------------------------------------
- // CFrameInfo_SetSourceFrame
- //-------------------------------------------------------------------------
-
- void CFrameInfo_SetSourceFrame(CFrameInfo* fi, Environment* ev, ODFrame* frame)
- {
- if ( frame != kODNULL )
- {
- // Create a proxy class to support the lazy internalization.
- CFrameProxy* proxy = CFrameProxy_Create();
- CFrameProxy_InitFrameProxyWithFrame(proxy, ev, frame);
-
- // Store the proxy source frame after clearing the old one.
- CFrameProxy_Delete(&(fi->fSourceFrame), ev);
- fi->fSourceFrame = proxy;
- }
- }
-
-
- //-------------------------------------------------------------------------
- // CFrameInfo_ReleaseSourceFrame
- //-------------------------------------------------------------------------
-
- void CFrameInfo_ReleaseSourceFrame(CFrameInfo* fi, Environment* ev)
- {
- CFrameProxy_Delete(&(fi->fSourceFrame), ev);
- }
-
-
- //-------------------------------------------------------------------------
- // CFrameInfo_IsFrameActive
- //-------------------------------------------------------------------------
-
- ODBoolean CFrameInfo_IsFrameActive(CFrameInfo* fi)
- {
- return fi->fFrameActive;
- }
-
-
- //-------------------------------------------------------------------------
- // CFrameInfo_SetFrameActive
- //-------------------------------------------------------------------------
-
- void CFrameInfo_SetFrameActive(CFrameInfo* fi, ODBoolean active)
- {
- fi->fFrameActive = active;
- }
-
-
- //-------------------------------------------------------------------------
- // CFrameInfo_FrameNeedsReactivating
- //-------------------------------------------------------------------------
-
- ODBoolean CFrameInfo_FrameNeedsReactivating(CFrameInfo* fi)
- {
- return fi->fFrameReactivate;
- }
-
-
- //-------------------------------------------------------------------------
- // CFrameInfo_SetFrameReactivate
- //-------------------------------------------------------------------------
-
- void CFrameInfo_SetFrameReactivate(CFrameInfo* fi, ODBoolean reactivate)
- {
- fi->fFrameReactivate = reactivate;
- }
-
-
- //-------------------------------------------------------------------------
- // CFrameInfo_SetActiveFacet
- //-------------------------------------------------------------------------
-
- void CFrameInfo_SetActiveFacet(CFrameInfo* fi, ODFacet* facet)
- {
- fi->fActiveFacet = facet;
- }
-
-
- //-------------------------------------------------------------------------
- // CFrameInfo_SetActiveFacet
- //-------------------------------------------------------------------------
-
- ODFacet* CFrameInfo_GetActiveFacet(CFrameInfo* fi)
- {
- return fi->fActiveFacet;
- }
-
-
- //-------------------------------------------------------------------------
- // CFrameInfo_GetSourceFrame
- //-------------------------------------------------------------------------
-
- ODFrame* CFrameInfo_GetSourceFrame(CFrameInfo* fi, Environment* ev)
- {
- return CFrameProxy_GetFrame(fi->fSourceFrame, ev);
- }
-
-
- //-------------------------------------------------------------------------
- // CFrameInfo_HasSourceFrame
- //-------------------------------------------------------------------------
-
- ODBoolean CFrameInfo_HasSourceFrame(CFrameInfo* fi)
- {
- return (fi->fSourceFrame != kODNULL);
- }
-
-
- //-------------------------------------------------------------------------
- // CFrameInfo_AcquirePartWindow
- //-------------------------------------------------------------------------
-
- ODWindow* CFrameInfo_AcquirePartWindow(CFrameInfo* fi, Environment* ev)
- {
- ODWindow* window = kODNULL;
- ODWindowState* windowState;
-
- if ( fi->fPartWindowID )
- {
- windowState = ODSession_GetWindowState(fi->fSession, ev);
- window = ODWindowState_AcquireWindow(windowState, ev, fi->fPartWindowID);
- if ( !window ) fi->fPartWindowID = kODNULLID;
- }
-
- return window;
- }
-
-
- //-------------------------------------------------------------------------
- // CFrameInfo_SetPartWindow
- //-------------------------------------------------------------------------
-
- void CFrameInfo_SetPartWindow(CFrameInfo* fi, Environment* ev, ODWindow* window)
- {
- fi->fPartWindowID = window ? ODWindow_GetID(window, ev) : kODNULLID;
- }
-
-
- //-------------------------------------------------------------------------
- // CFrameInfo_SetDependentFrame
- //-------------------------------------------------------------------------
-
- void CFrameInfo_SetDependentFrame(CFrameInfo* fi, Environment* ev, ODFrame* frame)
- {
- if ( frame != kODNULL )
- {
- // Create a proxy class to support the lazy internalization.
- CFrameProxy* proxy = CFrameProxy_Create();
- CFrameProxy_InitFrameProxyWithFrame(proxy, ev, frame);
-
- // Store the proxy dependent frame after clearing the old one.
- CFrameProxy_Delete(&(fi->fDependentFrame), ev);
- fi->fDependentFrame = proxy;
- }
- }
-
- //-------------------------------------------------------------------------
- // CFrameInfo_GetDependentFrame
- //-------------------------------------------------------------------------
-
- ODFrame* CFrameInfo_GetDependentFrame(CFrameInfo* fi, Environment* ev)
- {
- return (CFrameProxy_GetFrame(fi->fDependentFrame, ev));
- }
-
- //-------------------------------------------------------------------------
- // CFrameInfo_HasDependentFrame
- //-------------------------------------------------------------------------
-
- ODBoolean CFrameInfo_HasDependentFrame(CFrameInfo* fi)
- {
- return (fi->fDependentFrame != kODNULL);
- }
-
- //-------------------------------------------------------------------------
- // CFrameInfo_ReleaseDependentFrame
- //-------------------------------------------------------------------------
-
- void CFrameInfo_ReleaseDependentFrame(CFrameInfo* fi, Environment* ev)
- {
- CFrameProxy_Delete(&(fi->fDependentFrame), ev);
- }
-
- //-------------------------------------------------------------------------
- // CFrameInfo_SetShouldDisposeWindow
- //-------------------------------------------------------------------------
-
- void CFrameInfo_SetShouldDisposeWindow(CFrameInfo* fi, ODBoolean should)
- {
- fi->fShouldDisposeWindow = should;
- }
-
- //-------------------------------------------------------------------------
- // CFrameInfo_ShouldDisposeWindow
- //-------------------------------------------------------------------------
-
- ODBoolean CFrameInfo_ShouldDisposeWindow(CFrameInfo* fi)
- {
- return fi->fShouldDisposeWindow;
- }
-
-